package com.pan.kang.util.mock;


import net.datafaker.Faker;
import org.apache.commons.lang3.RandomUtils;

import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.UUID;

public class RandomTestDataUtil {

    private final static Faker ZH_FAKER = new Faker(new Locale("zh-CN"));

    private final static Faker EN_FAKER = new Faker();

    private final static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");


    public static Object getDataValue(String fieldType, String fieldName) {
        switch (fieldType) {
            case "java.lang.String":
                if (fieldName.contains("id")
                        || fieldName.contains("Id")) {
                    return String.format("\"%s\"", String.valueOf(UUID.randomUUID())
                            .replaceAll("-", ""));
                } else if (fieldName.contains("status")
                        || fieldName.contains("flag")) {
                    return String.format("\"%s\"", "Y");
                } else if (fieldName.contains("IP")
                        || fieldName.contains("ip")) {
                    return String.format("\"%s\"", ZH_FAKER.internet().ipV4Address());
                } else if (fieldName.contains("email")
                        || fieldName.contains("Email")) {
                    return String.format("\"%s\"", EN_FAKER.internet().emailAddress());
                } else if (fieldName.contains("phone")
                        || fieldName.contains("Phone")
                        || fieldName.contains("Mobile")
                        || fieldName.contains("mobile")
                        || fieldName.contains("number")
                        || fieldName.contains("Number")) {
                    return String.format("\"%s\"", ZH_FAKER.phoneNumber().cellPhone());
                } else if (fieldName.contains("address")
                        || fieldName.contains("Address")) {
                    return String.format("\"%s\"", ZH_FAKER.address().city());
                } else {
                    return String.format("\"%s\"", ZH_FAKER.name().name());
                }
            case "java.lang.Integer":
            case "int":
                return RandomUtils.nextInt(1, 999);
            case "java.lang.Long":
            case "long":
                return String.format("%sL", ZH_FAKER.number().randomNumber());
            case "java.lang.Boolean":
            case "boolean":
                return String.format("%s", false);
            case "java.lang.Double":
            case "double":
            case "java.lang.Float":
            case "float":
                return RandomUtils.nextFloat(0, 100);
            case "java.sql.Timestamp":
                return String.format("%s", "new Timestamp(System.currentTimeMillis())");
            case "java.util.Date":
                return String.format("%s", "new Date()");
            case "java.math.BigDecimal":
                return String.format("%s", "BigDecimal.ONE");
            case "java.util.List":
                return String.format("%s", "new ArrayList<>()");
            case "java.util.Map":
                return String.format("%s", "new HashMap<>()");
            case "java.util.Set":
                return String.format("%s", "new HashSet<>()");
            default:
                return String.format("%s", "null");
        }
    }
}
